authorization do
  role :admin do
    has_permission_on [:artists, :releases], :to => [:show, :edit, :new, :create, :update]
    has_permission_on [:forums, :forum_threads, :posts], :to => [:new, :create, :edit, :update, :destroy]
    has_permission_on :users, :to => [:show, :new, :create, :edit, :update, :destroy]
    has_permission_on :delete_requests, :to => [:new, :create, :edit, :update, :index, :show]
    has_permission_on :admins, :to => [:show, :update, :destroy]
    has_permission_on :password_resets, :to => [:admin_create]
  end

  role :guest do
    has_permission_on :artists, :to => [:show, :release_set]
    has_permission_on [:releases, :editions], :to => [:show]
    has_permission_on :songs, :to => [:show]
    has_permission_on :genres, :to => [:show]
    has_permission_on :labels, :to => [:show]
    has_permission_on [:forums, :forum_threads, :posts], :to => [:show]
    has_permission_on :images, :to => [:index]
    has_permission_on :home, :to => [:index, :random]
    has_permission_on :edits, :to => [:index]
    has_permission_on :searches, :to => [:show]
    has_permission_on :users, :to => [:new, :create, :show, :resend_activation]
  end

  role :moderator do
    has_permission_on [:forums, :forum_threads, :posts], :to => [:new, :create, :edit, :update, :destroy]
  end

  role :editor do
    has_permission_on :delete_requests, :to => [:new, :create, :edit, :update, :index, :show]
  end

  role :user do
    includes :guest
    has_permission_on :artists, :to => [:new, :create, :edit, :update]
    has_permission_on [:releases, :editions], :to => [:new, :create, :edit, :update]
    has_permission_on :songs, :to => [:new, :create, :edit, :update]
    has_permission_on :genres, :to => [:new, :create, :edit, :update]
    has_permission_on :labels, :to => [:new, :create, :edit, :update]
    has_permission_on :delete_requests, :to => [:new, :create]
    has_permission_on [:forum_threads, :posts, :reviews], :to => [:new, :create]
    has_permission_on :name_aliases, :to => [:create, :edit, :update, :destroy]
    has_permission_on :genre_links, :to => [:new, :create, :destroy]
    has_permission_on :memberships, :to => [:new, :create, :edit, :update, :show, :destroy]
    has_permission_on :select_search, :to => [:new, :create]
    has_permission_on :song_credits, :to => [:new, :create, :edit, :update, :destroy]
    has_permission_on :edition_credits, :to => [:new, :create, :edit, :update, :destroy]
    has_permission_on :artist_links, :to => [:new, :create, :destroy]
    has_permission_on :favorites, :to => [:create, :destroy]
    has_permission_on [:forums, :forum_threads, :posts, :reviews], :to => [:edit, :update, :destroy] do
      if_attribute :user => is { user }
    end
  end
end
